package com.box.modules.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.box.modules.report.dao.BoxRowDataDao;
import com.box.modules.report.entity.BoxRowDataEntity;
import com.box.modules.report.service.BoxRowDataService;
import com.box.modules.report.service.BoxRowProcessedService;
import com.box.modules.report.vo.ReportVO;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("boxRowDataService")
@Transactional
public class BoxRowDataServiceImpl extends ServiceImpl<BoxRowDataDao, BoxRowDataEntity> implements BoxRowDataService {

    @Autowired
    BoxRowProcessedService boxRowProcessedService;

    @Override
    public Boolean checkMessageId(String messageId) {
        LambdaQueryWrapper<BoxRowDataEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BoxRowDataEntity::getMessageId, messageId);

        if (this.getOne(queryWrapper) == null) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public Boolean addReport(ReportVO reportVO) {
        //新增到原始数据表
        BoxRowDataEntity boxRowDataEntity = new BoxRowDataEntity();
        boxRowDataEntity.setMessageId(reportVO.getMessageId());
        boxRowDataEntity.setBoxNo(reportVO.getBoxNo());
        boxRowDataEntity.setReportTime(reportVO.getReportTime());
        boxRowDataEntity.setTotalData(reportVO.getTotalData());
        boxRowDataEntity.setList(JSONArray.fromObject(reportVO.getList()).toString());
        return this.save(boxRowDataEntity);
    }

}
